class MainUI extends eui.Component {
	public topGroup: eui.Group;
	public rbtn1: eui.RadioButton;
	public rbtn2: eui.RadioButton;
	public rbtn3: eui.RadioButton;
	public rbtn4: eui.RadioButton;
	public contentGroup: eui.Group;
	public content1: eui.Group;
	public content2: eui.Group;
	public tweenGroup: eui.Group;



	public curContentIndex: number = 1;
	public isChanging; boolean;

	public constructor() {
		super();
		this.skinName = "MainSkin";
		this.once(eui.UIEvent.CREATION_COMPLETE, this.init, this);
	}

	private init() {
		this.width = this.stage.$stageWidth;
		this.rbtn1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRadioBtn, this);
		this.rbtn2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRadioBtn, this);
		this.rbtn3.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRadioBtn, this);
		this.rbtn4.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onRadioBtn, this);

	}
	private onRadioBtn(e: egret.TouchEvent) {
		if (this.isChanging) return;

		let endindex = e.currentTarget.name;
		if(endindex == this.curContentIndex) return;
		
		this.changeContent(this.curContentIndex, endindex);
	}
	private changeContent(startIndex, endIndex) {
		console.log("changeContent ",startIndex," ",endIndex);

		this["content"+startIndex].visible = false;
		this["content"+endIndex].visible = true;
		this.curContentIndex = endIndex;


		// this.isChanging = true;
		// var gridHeight = 120;
		// var height = this.stage.stageHeight;
		// var count = Math.ceil(height - this.contentGroup.top) / gridHeight;
		// for (var i = 0; i < count; i++) {
		// 	var rect = new eui.Rect(3000, gridHeight, Math.random()*256*256*256);
		// 	rect.x = -3000 - Math.floor(Math.random() * 1000);
		// 	rect.y = i * gridHeight;
		// 	this.tweenGroup.addChild(rect);
		// }

		// egret.Tween.get(this.tweenGroup)
		// 	.set({x:0})
		// 	.to({x:2000},500)
		// 	.call(()=>{
		// 		this["content"+startIndex].visible = false;
		// 		this["content"+endIndex].visible = true;
		// 		this.curContentIndex = endIndex;
		// 	})
		// 	.to({x:5000},500)
		// 	.call(()=>{
		// 		egret.Tween.removeTweens(this.tweenGroup);
		// 		this.tweenGroup.removeChildren();
		// 		this.isChanging = false;
		// 	})
	}

	private color16() {//十六进制颜色随机
		var r = Math.floor(Math.random() * 256);
		var g = Math.floor(Math.random() * 256);
		var b = Math.floor(Math.random() * 256);
		var color = '0x' + r.toString(16) + g.toString(16) + b.toString(16);
		return color;
	}
}